  // pages/recycling/recyclingKinds/recyclingKinds.js
const app = getApp();
const WxParse = require('../../../wxParse/wxParse.js');
import Api from '../../../utils/http';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recyclePrice: [], //可回收
    // harmful: [], //有害
    // wet: [], //湿垃圾
    // dry: [], //干垃圾
    searchFlag: true,
    launch: '',//关键字
  },
  // //搜索
  // toSearchKeyWord: function () {
  //   wx.navigateTo({
  //     url: '/pages/recycling/recyclingList/recyclingList?type=2',
  //   })
  // },
  //搜索
  toSearchKeyWord: function () {
    this.setData({
      searchFlag: false
    })
  },
  search: function (e) {
    var that = this;
    that.setData({
      launch: e.detail.value
    });
    this.getRecyclePrice();
  },
  //回收价格列表
  recyclingList: function (e) {
    var that = this;
    var {
      recyclePrice
    } = that.data
    let index = e.currentTarget.dataset.index
    console.log(e.currentTarget.dataset.index)
    console.log(that.data)
    var lidr = recyclePrice[index].id
      wx.navigateTo({
        url: `/pages/recycling/recyclingList/recyclingList?id=${lidr}&type=1`,
      })
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getRecyclePrice();
    // that.getHarmful();
    // that.getWet();
    // that.getDry();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  //可回收回收价格
  getRecyclePrice: function () {
    var that = this;
    var param = {
      pageNum: 1,
      pageSize: 9,
      keyword:that.data.launch
    }
    console.log(param)
    Api.ajax("/app/Zarticle/recyclePrice", param).then(res => {
      console.log(res)
      console.log(res.data[0])
      if (res.code == 200) {
        var newsArr = res.data;
        for (let i = 0; i < newsArr.length; i++) {
          WxParse.wxParse('content' + i, 'html', newsArr[i].content, that);
          if (i === newsArr.length - 1) {
            WxParse.wxParseTemArray("newsArray",'content', newsArr.length, that)
          }
        }
        that.setData({
          recyclePrice: newsArr
        });
      }
    })
  },
  //有害回收价格
  // getHarmful: function () {
  //   var that = this;
  //   var param = {
  //     pageNum: 1,
  //     pageSize: 9
  //   }
  //   console.log(param)
  //   Api.ajax("/app/Zarticle/recyclePrice", param).then(res => {
  //     console.log(res)
  //     if (res.code == 200) {
  //       var article = res.data[1].content;
  //       WxParse.wxParse('article', 'html', article, that);
  //       that.setData({
  //         harmful: res.data[1]
  //       });
  //     }
  //   })
  // },
  // //湿回收价格
  // getWet: function () {
  //   var that = this;
  //   var param = {
  //     pageNum: 1,
  //     pageSize: 9
  //   }
  //   console.log(param)
  //   Api.ajax("/app/Zarticle/recyclePrice", param).then(res => {
  //     console.log(res)
  //     if (res.code == 200) {
  //       var article = res.data[2].content;
  //       WxParse.wxParse('article', 'html', article, that);
  //       that.setData({
  //         wet: res.data[2]
  //       });
  //     }
  //   })
  // },
  // //干垃圾回收价格
  // getDry: function () {
  //   var that = this;
  //   var param = {
  //     pageNum: 1,
  //     pageSize: 9
  //   }
  //   console.log(param)
  //   Api.ajax("/app/Zarticle/recyclePrice", param).then(res => {
  //     console.log(res)
  //     if (res.code == 200) {
  //       console.log(res.data[3])
  //       var article = res.data[3].content;

  //       WxParse.wxParse('article', 'html', article, that);
  //       that.setData({
  //         dry: res.data[3]
  //       });
  //     }
  //   })
  // },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})